<h3>
	<%=l(:label_how_busy_mypage_title)%>
</h3>

<%
# Get Settings.
regular_work_hours = Setting.plugin_redmine_how_busy['regular_work_hours'].to_f
num_past_days = Setting.plugin_redmine_how_busy['mypage_num_past_days'].to_i
num_future_days = Setting.plugin_redmine_how_busy['mypage_num_future_days'].to_i

# Get Issues.
issues = Issue.find(:all,
	:conditions => ["assigned_to_id=? AND #{IssueStatus.table_name}.is_closed=? AND #{Project.table_name}.status=#{Project::STATUS_ACTIVE}", @user.id, false],
	:include => [ :status, :project, :tracker, :priority ],
	:order => "#{Enumeration.table_name}.position DESC, #{Issue.table_name}.updated_on DESC")

# Get Time Entries.
entries = TimeEntry.find(:all,
				:conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - num_past_days, Date.today + num_future_days],
				:order => "#{TimeEntry.table_name}.spent_on ASC, #{TimeEntry.table_name}.updated_on ASC")
%>
<% form_tag({}) do %>
	<div class="how_busy_main_block">
		<table class="how_busy_table" style="width:<%= (num_past_days + num_future_days + 2) * 100 %>px">
			<thead>
				<%=
					render :partial => 'how_busy/header.rhtml', :locals => {
						:date_from => Date.today - num_past_days,
						:date_to => Date.today + num_future_days
					}
				%>
			</thead>
			<tbody>
				<%=
					render :partial => 'how_busy/row.rhtml', :locals => {
						:regular_work_hours => regular_work_hours,
						:date_from => Date.today - num_past_days,
						:date_to => Date.today + num_future_days,
						:user_name => @user.name,
						:issues => issues,
						:entries => entries
					}
				%>
			</tbody>
		</table>
	</div>
<% end %>

<% content_for :header_tags do %>
    <%= stylesheet_link_tag 'how_busy', :plugin => 'redmine_how_busy' %>
	<%= javascript_include_tag 'how_busy', :plugin => 'redmine_how_busy' %>
<% end %>
